class Category < ActiveRecord::Base
  belongs_to :group
  has_many :sub_categories
  has_many :advertisments , :through=> :sub_categories
#  has_and_belongs_to_many :user_types
  has_many :user_type_category_maps
  has_many :user_types              , :conditions => ["relation_type = ?" , 0] , :through => :user_type_category_maps
  has_many :user_types_for_posting  , :conditions => ["relation_type = ?" , 1], :source => :user_type , :through => :user_type_category_maps

  def label_for_userType(userType)
    $category_labels[self.stripped_name][userType]
  end

  def form_labels
    all_form_fields = self.sub_categories.collect {|x| (x.advertisment_form_field.nil?) ? nil : x.advertisment_form_field }.compact.flatten
    all_labels      = all_form_fields.collect {|y| y[:input_type][1] if y.class == Hash and (not y[:input_type].nil?) }.compact.uniq.flatten
    return all_labels
  end
end
